
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 12/03/2013 15:52:32
-- Generated from EDMX file: C:\Users\hp\Documents\Visual Studio 2012\Projects\McvParis-vert\McvParis-vert\McvParis-vert.Application\Models\Model.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [vert-paris];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_ItineraireCommentaire]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Commentaires] DROP CONSTRAINT [FK_ItineraireCommentaire];
GO
IF OBJECT_ID(N'[dbo].[FK_UtilisateurCommentaire]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Commentaires] DROP CONSTRAINT [FK_UtilisateurCommentaire];
GO
IF OBJECT_ID(N'[dbo].[FK_EvenementItineraire]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Evenements] DROP CONSTRAINT [FK_EvenementItineraire];
GO
IF OBJECT_ID(N'[dbo].[FK_UtilisateurEvenement]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Evenements] DROP CONSTRAINT [FK_UtilisateurEvenement];
GO
IF OBJECT_ID(N'[dbo].[FK_GalerieItineraire]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Galeries] DROP CONSTRAINT [FK_GalerieItineraire];
GO
IF OBJECT_ID(N'[dbo].[FK_Critere_ItineraireCritere]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Criteres] DROP CONSTRAINT [FK_Critere_ItineraireCritere];
GO
IF OBJECT_ID(N'[dbo].[FK_ItineraireCritere_Itineraire]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Critere_Itineraire] DROP CONSTRAINT [FK_ItineraireCritere_Itineraire];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Commentaires]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Commentaires];
GO
IF OBJECT_ID(N'[dbo].[Criteres]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Criteres];
GO
IF OBJECT_ID(N'[dbo].[Evenements]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Evenements];
GO
IF OBJECT_ID(N'[dbo].[Galeries]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Galeries];
GO
IF OBJECT_ID(N'[dbo].[Itineraires]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Itineraires];
GO
IF OBJECT_ID(N'[dbo].[Thematiques]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Thematiques];
GO
IF OBJECT_ID(N'[dbo].[Utilisateurs]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Utilisateurs];
GO
IF OBJECT_ID(N'[dbo].[Critere_Itineraire]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Critere_Itineraire];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Commentaires'
CREATE TABLE [dbo].[Commentaires] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Date_De_Publication] datetime  NOT NULL,
    [Date_De_Modification] datetime  NULL,
    [Contenu] nvarchar(max)  NOT NULL,
    [Utilisateur_Id] int  NOT NULL,
    [Itineraire_Id] int  NOT NULL
);
GO

-- Creating table 'Criteres'
CREATE TABLE [dbo].[Criteres] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Libelle] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Evenements'
CREATE TABLE [dbo].[Evenements] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Date] datetime  NOT NULL,
    [Utilisateur_Id] int  NOT NULL,
    [Itineraire_Id] int  NOT NULL
);
GO

-- Creating table 'Galeries'
CREATE TABLE [dbo].[Galeries] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Image] nvarchar(max)  NULL,
    [Itineraire_Id] int  NOT NULL
);
GO

-- Creating table 'Itineraires'
CREATE TABLE [dbo].[Itineraires] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Titre] nvarchar(max)  NOT NULL,
    [Longitude_Depart] nvarchar(max)  NOT NULL,
    [Latitude_Depart] nvarchar(max)  NOT NULL,
    [Longitude_Arrivee] nvarchar(max)  NOT NULL,
    [Latitude_Arrivee] nvarchar(max)  NOT NULL,
    [Note] nvarchar(max)  NULL,
    [Adresse] nvarchar(max)  NOT NULL,
    [Code_Postal] nvarchar(max)  NULL,
    [Ville] nvarchar(max)  NULL
);
GO

-- Creating table 'Thematiques'
CREATE TABLE [dbo].[Thematiques] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Libelle] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Utilisateurs'
CREATE TABLE [dbo].[Utilisateurs] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Nom] nvarchar(max)  NOT NULL,
    [Prenom] nvarchar(max)  NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [Adresse] nvarchar(max)  NULL,
    [Code_Postal] nvarchar(max)  NULL,
    [Ville] nvarchar(max)  NULL,
    [Pseudo] nvarchar(max)  NOT NULL,
    [Mot_De_Passe] nvarchar(max)  NOT NULL,
    [Date_De_Naissance] datetime  NOT NULL,
    [Statut] bit  NULL,
    [Date_Inscription] datetime  NOT NULL,
    [Derniere_Connexion] datetime  NOT NULL,
    [Avatar] nvarchar(max)  NULL
);
GO

-- Creating table 'Critere_Itineraire'
CREATE TABLE [dbo].[Critere_Itineraire] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Itineraire_Id] int  NOT NULL,
    [Critere_Id] int  NOT NULL
);
GO

-- Creating table 'Thematique_ItineraireSet'
CREATE TABLE [dbo].[Thematique_ItineraireSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Thematique_Id] int  NOT NULL,
    [Itineraire_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Commentaires'
ALTER TABLE [dbo].[Commentaires]
ADD CONSTRAINT [PK_Commentaires]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Criteres'
ALTER TABLE [dbo].[Criteres]
ADD CONSTRAINT [PK_Criteres]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Evenements'
ALTER TABLE [dbo].[Evenements]
ADD CONSTRAINT [PK_Evenements]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Galeries'
ALTER TABLE [dbo].[Galeries]
ADD CONSTRAINT [PK_Galeries]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Itineraires'
ALTER TABLE [dbo].[Itineraires]
ADD CONSTRAINT [PK_Itineraires]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Thematiques'
ALTER TABLE [dbo].[Thematiques]
ADD CONSTRAINT [PK_Thematiques]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Utilisateurs'
ALTER TABLE [dbo].[Utilisateurs]
ADD CONSTRAINT [PK_Utilisateurs]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Critere_Itineraire'
ALTER TABLE [dbo].[Critere_Itineraire]
ADD CONSTRAINT [PK_Critere_Itineraire]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Thematique_ItineraireSet'
ALTER TABLE [dbo].[Thematique_ItineraireSet]
ADD CONSTRAINT [PK_Thematique_ItineraireSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Itineraire_Id] in table 'Commentaires'
ALTER TABLE [dbo].[Commentaires]
ADD CONSTRAINT [FK_ItineraireCommentaire]
    FOREIGN KEY ([Itineraire_Id])
    REFERENCES [dbo].[Itineraires]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ItineraireCommentaire'
CREATE INDEX [IX_FK_ItineraireCommentaire]
ON [dbo].[Commentaires]
    ([Itineraire_Id]);
GO

-- Creating foreign key on [Utilisateur_Id] in table 'Commentaires'
ALTER TABLE [dbo].[Commentaires]
ADD CONSTRAINT [FK_UtilisateurCommentaire]
    FOREIGN KEY ([Utilisateur_Id])
    REFERENCES [dbo].[Utilisateurs]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UtilisateurCommentaire'
CREATE INDEX [IX_FK_UtilisateurCommentaire]
ON [dbo].[Commentaires]
    ([Utilisateur_Id]);
GO

-- Creating foreign key on [Itineraire_Id] in table 'Evenements'
ALTER TABLE [dbo].[Evenements]
ADD CONSTRAINT [FK_EvenementItineraire]
    FOREIGN KEY ([Itineraire_Id])
    REFERENCES [dbo].[Itineraires]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EvenementItineraire'
CREATE INDEX [IX_FK_EvenementItineraire]
ON [dbo].[Evenements]
    ([Itineraire_Id]);
GO

-- Creating foreign key on [Utilisateur_Id] in table 'Evenements'
ALTER TABLE [dbo].[Evenements]
ADD CONSTRAINT [FK_UtilisateurEvenement]
    FOREIGN KEY ([Utilisateur_Id])
    REFERENCES [dbo].[Utilisateurs]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UtilisateurEvenement'
CREATE INDEX [IX_FK_UtilisateurEvenement]
ON [dbo].[Evenements]
    ([Utilisateur_Id]);
GO

-- Creating foreign key on [Itineraire_Id] in table 'Galeries'
ALTER TABLE [dbo].[Galeries]
ADD CONSTRAINT [FK_GalerieItineraire]
    FOREIGN KEY ([Itineraire_Id])
    REFERENCES [dbo].[Itineraires]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_GalerieItineraire'
CREATE INDEX [IX_FK_GalerieItineraire]
ON [dbo].[Galeries]
    ([Itineraire_Id]);
GO

-- Creating foreign key on [Itineraire_Id] in table 'Critere_Itineraire'
ALTER TABLE [dbo].[Critere_Itineraire]
ADD CONSTRAINT [FK_ItineraireCritere_Itineraire]
    FOREIGN KEY ([Itineraire_Id])
    REFERENCES [dbo].[Itineraires]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ItineraireCritere_Itineraire'
CREATE INDEX [IX_FK_ItineraireCritere_Itineraire]
ON [dbo].[Critere_Itineraire]
    ([Itineraire_Id]);
GO

-- Creating foreign key on [Critere_Id] in table 'Critere_Itineraire'
ALTER TABLE [dbo].[Critere_Itineraire]
ADD CONSTRAINT [FK_CritereCritere_Itineraire]
    FOREIGN KEY ([Critere_Id])
    REFERENCES [dbo].[Criteres]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CritereCritere_Itineraire'
CREATE INDEX [IX_FK_CritereCritere_Itineraire]
ON [dbo].[Critere_Itineraire]
    ([Critere_Id]);
GO

-- Creating foreign key on [Thematique_Id] in table 'Thematique_ItineraireSet'
ALTER TABLE [dbo].[Thematique_ItineraireSet]
ADD CONSTRAINT [FK_ThematiqueThematique_Itineraire]
    FOREIGN KEY ([Thematique_Id])
    REFERENCES [dbo].[Thematiques]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ThematiqueThematique_Itineraire'
CREATE INDEX [IX_FK_ThematiqueThematique_Itineraire]
ON [dbo].[Thematique_ItineraireSet]
    ([Thematique_Id]);
GO

-- Creating foreign key on [Itineraire_Id] in table 'Thematique_ItineraireSet'
ALTER TABLE [dbo].[Thematique_ItineraireSet]
ADD CONSTRAINT [FK_ItineraireThematique_Itineraire]
    FOREIGN KEY ([Itineraire_Id])
    REFERENCES [dbo].[Itineraires]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ItineraireThematique_Itineraire'
CREATE INDEX [IX_FK_ItineraireThematique_Itineraire]
ON [dbo].[Thematique_ItineraireSet]
    ([Itineraire_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------